    

  <?php form_head($this->user->current_controller(),"");
          $user = $this->user->get();
	  ?>
          <?php text_field("name","ชื่อผู้ขอเบิกจ่าย",array("name" =>$user["firstname"]." ".$user["lastname"]),"disable"); ?>
         
            <?php area_field("detail","รายละเอียดขอเบิกจ่าย",null,1); ?>
            
            <?php 

		 $rows =  $this->db->query("select place_id,  place_name from  place")->result_array();

		 select_field("place_id","ห้องปฎิบัติการ/สถานที่",$rows,"place_name","โปรดเลือก",0,null,"",2); 

		//select_field($name,$label,$rows,$label_value,$row,$cleaner = 0,$first_label="โปรดเลือก",$class ="",$type=1)

		 ?>
		 <br/>
กรอกข้อมูลความต้องการใช้งานวัสดุ-ครุภัณฑ์
       <?php 
$rows = $this->db->query("select * from meterial_base_categories order by sort_order asc")->result_array();
foreach($rows as $base){
$sql ="SELECT
material_categories.category_name,
material_categories.cat_base_id,
material_categories.category_id,


(select  COALESCE(sum( amount_total  ),0 ) from inventory_views where material_categories.category_id =  inventory_views.category_id ) as total
,(select  COALESCE(sum( allocation_total  ),0 ) from inventory_views where material_categories.category_id =  inventory_views.category_id ) as allocation_total

FROM
material_categories where cat_base_id = ".$base['cat_base_id'];
$cats =  $this->db->query($sql)->result_array(); ?>

<table class="list" >
          <tbody><tr class=" odd">
            <th style="width:200px;" ><?php echo $base["cat_base_name"]; ?></th>
            
            <th style="width:70px;">จำนวนที่มี</th>
          
             <th style="width:70px;">ยังไม่ได้จัดสรร</th>
             <th style="width:70px;">ความต้องการเพิ่มเติม</th>
          </tr>
         <?php
          $i = 1;
          foreach($cats as $row){ ?>
        
          <tr class="<?php if($i++%2){ echo "even";} ?>" >
            
            
            <td><?php echo $row['category_name']; ?></td>
            
            <td><?php echo $row['total']; ?></td>
            
            <td><?php echo ($row['total'] - $row['allocation_total']); ?></td>
            <td><input style="width:40px;" name="cat_values[<?php echo $row["category_id"] ?>]" type="text" value="0"  /></td>
          </tr>
          <?php } } ?>
        </tbody></table>

         <?php //print_r($_POST); ?>
  <?php form_footer("บันทึก"); ?>
         